package org.wlldTest.gmm;

import com.alibaba.fastjson.JSONObject;
import org.dromara.easyai.entity.GMMBody;
import org.dromara.easyai.entity.GMModel;
import org.dromara.easyai.matrixTools.Matrix;
import org.dromara.easyai.tools.GMClustering;

import java.util.Random;

/**
 * @author lidapeng
 * @time 2025/10/27 17:23
 */
public class Test {
    public static GMClustering gmClustering;

    static {
        try {
            gmClustering = new GMClustering(2, 1000, 1, 3);
            //gmClustering.insertModel(JSONObject.parseObject(Data.data, GMModel.class));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws Exception {
        study();
        test();
    }

    public static void test() throws Exception {
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            System.out.println("i======" + i);
            float a1 = random.nextFloat() * 0.1f;
            float b1 = a1 + 0.2f;
            float c1 = a1 - 0.1f;
            float a2 = a1 + 0.3f;
            float b2 = a1 + 0.5f;
            float c2 = a2 + 0.7f;
            Matrix matrix1 = new Matrix(1, 3);
            Matrix matrix2 = new Matrix(1, 3);
            matrix1.setNub(0, 0, a1);
            matrix1.setNub(0, 1, b1);
            matrix1.setNub(0, 2, c1);
            matrix2.setNub(0, 0, a2);
            matrix2.setNub(0, 1, b2);
            matrix2.setNub(0, 2, c2);
            GMMBody gmmBody1 = gmClustering.getType(matrix1);
            GMMBody gmmBody2 = gmClustering.getType(matrix2);
            System.out.println("1type:" + gmmBody1.getType());
            System.out.println("1power:" + gmmBody1.getPower());
            System.out.println("2type:" + gmmBody2.getType());
            System.out.println("2power:" + gmmBody2.getPower());

        }
    }

    public static void study() throws Exception {
        Random random = new Random();
        for (int i = 0; i < 100; i++) {
            float a1 = random.nextFloat() * 0.1f;
            float b1 = a1 + 0.2f;
            float c1 = a1 - 0.1f;
            float a2 = a1 + 0.3f;
            float b2 = a1 + 0.5f;
            float c2 = a2 + 0.7f;
            Matrix matrix1 = new Matrix(1, 3);
            Matrix matrix2 = new Matrix(1, 3);
            matrix1.setNub(0, 0, a1);
            matrix1.setNub(0, 1, b1);
            matrix1.setNub(0, 2, c1);
            matrix2.setNub(0, 0, a2);
            matrix2.setNub(0, 1, b2);
            matrix2.setNub(0, 2, c2);
            gmClustering.insertParameter(matrix1);
            gmClustering.insertParameter(matrix2);
        }
        gmClustering.start();
        GMModel gmModel = gmClustering.getModel();
        System.out.println(JSONObject.toJSONString(gmModel));
    }
}
